package cn.oms.oms.controller;


import cn.oms.oms.entity.Picking;
import cn.oms.oms.entity.Prescription;
import cn.oms.oms.service.IPickingService;
import cn.oms.oms.service.IPrescriptionService;
import cn.oms.oms.vo.PickingVo;
import cn.oms.oms.vo.PrescriptionVo;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author AllenChen曾晨
 * @since 2022-04-29
 */
@RestController
@RequestMapping("/oms/prescription")
@Slf4j
public class PrescriptionController {

    @Autowired
    public IPrescriptionService prescriptionService;

    /**
     * 根据查询条件查询处方列表
     * @param prescriptionVo
     * @return
     */
    @PostMapping("/selectPrescriptionList")
    public PageInfo<Prescription> selectPrescriptionList(PrescriptionVo prescriptionVo){
        if(prescriptionVo.getPageNum()==null||prescriptionVo.getPageNum()==0){
            prescriptionVo.setPageNum(1);
        }
        if(prescriptionVo.getPageSize()==null||prescriptionVo.getPageSize()==0){
            prescriptionVo.setPageSize(10);
        }
        log.debug("接收到信息:{}",prescriptionVo);
        PageInfo<Prescription> pageInfo = prescriptionService.selectPrescriptionList(prescriptionVo);
        return pageInfo;
    }

    /**
     * 根据处方号查询详情
     * @param prescriptionVo
     * @return
     */
    @PostMapping("/selectPrescriptionDetail")
    public Prescription selectPrescriptionDetail(PrescriptionVo prescriptionVo){
        log.debug("接收到信息:{}",prescriptionVo);
        Prescription prescription = prescriptionService.selectPrescriptionDetail(prescriptionVo);
        return prescription;
    }

    /**
     * 新增处方
     * @param prescriptionVo
     * @return
     */
    @PostMapping("/addPrescription")
    public String addPrescription(PrescriptionVo prescriptionVo){
        log.debug("接收到信息:{}",prescriptionVo);
        String res = prescriptionService.addPrescription(prescriptionVo);
        return res;
    }
    /**
     * 修改处方
     * @param prescriptionVo
     * @return
     */
    @PostMapping("/updatePrescription")
    public String updatePicking(PrescriptionVo prescriptionVo){
        log.debug("接收到信息:{}",prescriptionVo);
        String res = prescriptionService.updatePrescription(prescriptionVo);
        return res;
    }
    /**
     * 删除处方
     * @param id
     * @return
     */
    @GetMapping("/deletePrescription/{id}")
    public String deletePrescription(@PathVariable Integer id){
        log.debug("接收到信息:{}",id);
        String res = prescriptionService.deletePrescription(id);
        return res;
    }
    /**
     * 审方
     * @param prescriptionVo
     * @return
     */
    @PostMapping("/vetting")
    public String vetting(PrescriptionVo prescriptionVo){
        log.debug("接收到信息:{}",prescriptionVo);
        String res = prescriptionService.vetting(prescriptionVo);
        return res;
    }


}
